'\" t
.TH "SD_BUS_MESSAGE_NEW" "3" "" "systemd 257.1" "sd_bus_message_new"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
sd_bus_message_new, sd_bus_message_ref, sd_bus_message_unref, sd_bus_message_unrefp, SD_BUS_MESSAGE_METHOD_CALL, SD_BUS_MESSAGE_METHOD_RETURN, SD_BUS_MESSAGE_METHOD_ERROR, SD_BUS_MESSAGE_SIGNAL, sd_bus_message_get_bus \- Create a new bus message object and create or destroy references to it
.SH "SYNOPSIS"
.sp
.ft B
.nf
#include <systemd/sd\-bus\&.h>
.fi
.ft
.sp
.ft B
.nf
enum {
      \fBSD_BUS_MESSAGE_METHOD_CALL\fR,
      \fBSD_BUS_MESSAGE_METHOD_RETURN\fR,
      \fBSD_BUS_MESSAGE_METHOD_ERROR\fR,
      \fBSD_BUS_MESSAGE_SIGNAL\fR,
};
.fi
.ft
.HP \w'int\ sd_bus_message_new('u
.BI "int sd_bus_message_new(sd_bus\ *" "bus" ", sd_bus_message\ **" "m" ", uint8_t\ " "type" ");"
.HP \w'sd_bus_message\ *sd_bus_message_ref('u
.BI "sd_bus_message *sd_bus_message_ref(sd_bus_message\ *" "m" ");"
.HP \w'sd_bus_message\ *sd_bus_message_unref('u
.BI "sd_bus_message *sd_bus_message_unref(sd_bus_message\ *" "m" ");"
.HP \w'void\ sd_bus_message_unrefp('u
.BI "void sd_bus_message_unrefp(sd_bus_message\ **" "mp" ");"
.HP \w'sd_bus\ *sd_bus_message_get_bus('u
.BI "sd_bus *sd_bus_message_get_bus(sd_bus_message\ *" "m" ");"
.SH "DESCRIPTION"
.PP
\fBsd_bus_message_new()\fR
creates a new bus message object attached to the bus
\fIbus\fR
and returns it in the output parameter
\fIm\fR\&. This object is reference\-counted, and will be destroyed when all references are gone\&. Initially, the caller of this function owns the sole reference to the message object\&. Note that the message object holds a reference to the bus object, so the bus object will not be destroyed as long as the message exists\&.
.PP
Note: this is a low\-level call\&. In most cases functions like
\fBsd_bus_message_new_method_call\fR(3),
\fBsd_bus_message_new_method_error\fR(3),
\fBsd_bus_message_new_method_return\fR(3), and
\fBsd_bus_message_new_signal\fR(3)
that create a message of a certain type and initialize various fields are easier to use\&.
.PP
The
\fItype\fR
parameter specifies the type of the message\&. It must be one of
\fBSD_BUS_MESSAGE_METHOD_CALL\fR
\(em a method call,
\fBSD_BUS_MESSAGE_METHOD_RETURN\fR
\(em a method call reply,
\fBSD_BUS_MESSAGE_METHOD_ERROR\fR
\(em an error reply to a method call,
\fBSD_BUS_MESSAGE_SIGNAL\fR
\(em a broadcast message with no reply\&.
.PP
The flag to allow interactive authorization is initialized based on the current value set in the bus object, see
\fBsd_bus_set_allow_interactive_authorization\fR(3)\&. This may be changed using
\fBsd_bus_message_set_allow_interactive_authorization\fR(3)\&.
.PP
\fBsd_bus_message_ref()\fR
increases the internal reference counter of
\fIm\fR
by one\&.
.PP
\fBsd_bus_message_unref()\fR
decreases the internal reference counter of
\fIm\fR
by one\&. Once the reference count has dropped to zero, message object is destroyed and cannot be used anymore, so further calls to
\fBsd_bus_message_ref()\fR
or
\fBsd_bus_message_unref()\fR
are illegal\&.
.PP
\fBsd_bus_message_unrefp()\fR
is similar to
\fBsd_bus_message_unref()\fR
but takes a pointer to a pointer to an
\fBsd_bus_message\fR
object\&. This call is useful in conjunction with GCC\*(Aqs and LLVM\*(Aqs
\m[blue]\fBClean\-up Variable Attribute\fR\m[]\&\s-2\u[1]\d\s+2\&. See
\fBsd_bus_new\fR(3)
for an example how to use the cleanup attribute\&.
.PP
\fBsd_bus_message_ref()\fR
and
\fBsd_bus_message_unref()\fR
execute no operation if the passed in bus message object address is
\fBNULL\fR\&.
\fBsd_bus_message_unrefp()\fR
will first dereference its argument, which must not be
\fBNULL\fR, and will execute no operation if
\fIthat\fR
is
\fBNULL\fR\&.
.PP
\fBsd_bus_message_get_bus()\fR
returns the bus object that message
\fIm\fR
is attached to\&.
.SH "RETURN VALUE"
.PP
On success,
\fBsd_bus_message_new()\fR
returns 0 or a positive integer\&. On failure, it returns a negative errno\-style error code\&.
.PP
\fBsd_bus_message_ref()\fR
always returns the argument\&.
.PP
\fBsd_bus_message_unref()\fR
always returns
\fBNULL\fR\&.
.PP
\fBsd_bus_message_get_bus()\fR
always returns the bus object\&.
.SS "Errors"
.PP
Returned errors may indicate the following problems:
.PP
\fB\-EINVAL\fR
.RS 4
Specified
\fItype\fR
is invalid\&.
.RE
.PP
\fB\-ENOTCONN\fR
.RS 4
The bus parameter
\fIbus\fR
is
\fBNULL\fR
or the bus is not connected\&.
.RE
.PP
\fB\-ENOMEM\fR
.RS 4
Memory allocation failed\&.
.RE
.SH "NOTES"
.PP
Functions described here are available as a shared library, which can be compiled against and linked to with the
\fBlibsystemd\fR\ \&\fBpkg-config\fR(1)
file\&.
.PP
The code described here uses
\fBgetenv\fR(3), which is declared to be not multi\-thread\-safe\&. This means that the code calling the functions described here must not call
\fBsetenv\fR(3)
from a parallel thread\&. It is recommended to only do calls to
\fBsetenv()\fR
from an early phase of the program when no other threads have been started\&.
.SH "HISTORY"
.PP
\fBsd_bus_message_new()\fR,
\fBsd_bus_message_ref()\fR,
\fBsd_bus_message_unref()\fR,
\fBsd_bus_message_unrefp()\fR, and
\fBsd_bus_message_get_bus()\fR
were added in version 240\&.
.SH "SEE ALSO"
.PP
\fBsystemd\fR(1), \fBsd-bus\fR(3), \fBsd_bus_new\fR(3), \fBsd_bus_message_new_method_call\fR(3), \fBsd_bus_message_new_method_error\fR(3), \fBsd_bus_message_new_method_return\fR(3), \fBsd_bus_message_new_signal\fR(3)
.SH "NOTES"
.IP " 1." 4
Clean-up Variable Attribute
.RS 4
\%https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
.RE
